package com.boc.address.model;

import com.boc.address.bean.AddressListBean;
import com.boc.address.contract.AddressListContract;
import com.boc.address.http.AddressApi;

import java.util.List;

import demo.bocweb.com.sdk.baseApi.AppUrl;
import demo.bocweb.com.sdk.apiHelper.RetrofitCreateHelper;
import demo.bocweb.com.sdk.apiHelper.RxHelper;
import demo.bocweb.com.sdk.base.BaseModel;
import demo.bocweb.com.sdk.base.bean.BaseBean;
import io.reactivex.Observable;
import okhttp3.RequestBody;

/**
 * Created by zhelun on 2018/2/2.
 */

public class AddressListModel extends BaseModel implements AddressListContract.IAddressListModel {

    public static AddressListModel newInstance() {
        return new AddressListModel();
    }

    @Override
    public Observable<BaseBean<List<AddressListBean>>> getAddressList() {
        return RetrofitCreateHelper.createApi(AddressApi.class, AppUrl.BASE_URL)
                .getAddressList()
                .compose(RxHelper.<BaseBean<List<AddressListBean>>>rxSchedulerHelper());
    }

    @Override
    public Observable<BaseBean> setDefaultAddress(RequestBody body) {
        return RetrofitCreateHelper.createApi(AddressApi.class, AppUrl.BASE_URL)
                .setDefault(body)
                .compose(RxHelper.<BaseBean>rxSchedulerHelper());
    }

    @Override
    public Observable<BaseBean> deleteAddress(RequestBody body) {
        return RetrofitCreateHelper.createApi(AddressApi.class, AppUrl.BASE_URL)
                .delete(body)
                .compose(RxHelper.<BaseBean>rxSchedulerHelper());
    }
}
